package com.dkm.dkmproject.action;


import com.dkm.dkmproject.domain.WalletTb;
import com.dkm.dkmproject.service.IWalletTbService;
import com.dkm.dkmproject.utils.Message;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 钱包表 前端控制器
 * </p>
 *
 * @author 周佳佳
 * @since 2020-04-26
 */
@RestController
@RequestMapping("/dkm.dkmproject/walletTb")
@Api(description = "我的钱包接口文档")
public class WalletTbController {
    @Autowired
    IWalletTbService walletTbService;
    /**
     * 增加用户钱包表
     * @param walletTbw
     * @return
     */
    @ApiOperation(value = " 增加用户的钱包接口", notes = "成功则返回成功，失败返回失败")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "waId", value = "钱包主键"),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "userId", value = "用户id",required = true),
            @ApiImplicitParam(paramType = "query", dataType = "BigDecimal", name = "money", value = "余额")
    })
    @ApiResponses({
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "服务器拒绝请求"),
            @ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对"),
            @ApiResponse(code = 500, message = "后台报错"),
            @ApiResponse(code = 200, message = "返回成功")
    })
    @PostMapping("/addWalletTb")
    public Message addWalletTb(WalletTb walletTbw){
        walletTbw.setMoney(BigDecimal.valueOf(0));
        Message message=new Message();
        int rows=walletTbService.addWalletTb(walletTbw);
        if(rows>0){
            message.setMsg("增加成功");
            message.setNum(1);
        }else{
            message.setMsg("失败");
            message.setNum(0);
        }
        return message;
    }

    /**
     * 根据用户的id查钱包余额
     * @param userId
     * @return
     */
    @ApiOperation(value = " 根据用户的id查钱包余额", notes = "成功则返回数据，失败返回空")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "waId", value = "钱包主键"),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "userId", value = "用户id",required = true),
            @ApiImplicitParam(paramType = "query", dataType = "BigDecimal", name = "money", value = "余额")
    })
    @ApiResponses({
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "服务器拒绝请求"),
            @ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对"),
            @ApiResponse(code = 500, message = "后台报错"),
            @ApiResponse(code = 200, message = "返回成功")
    })
    @GetMapping("/findByUserId")
    public List<WalletTb> findByUserId(String userId){
        if(!StringUtils.isEmpty(userId)){
            List<WalletTb> list=walletTbService.findUserId(Integer.valueOf(userId));
            return list;
        }else{
            return null;
        }
    }
}
